<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item label="项目名称">
          <el-input v-model="queryParam.qry_projectname" placeholder="请输入名称关键词" @keyup.enter.native="doQuery"></el-input>
        </el-form-item>
        <el-form-item label="项目级别">
          <el-select v-model="projectlevelList" multiple placeholder="请选择项目级别" style="width:190px">
            <el-option v-for="item in codeModel.projectlevelList" :key="item.code" :label="item.name" :value="item.code"> </el-option>
          </el-select>
        </el-form-item>
      </template>
    </tl-list-search>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :row-style="tableRowStyle" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column> -->
        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
        <el-table-column prop="deptname" label="所属部门" width="95px" sortable="custom" sort-by="deptname" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectcode" label="项目编号" width="150px" sortable="custom" sort-by="projectcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目名称" min-width="300px" sortable="custom" sort-by="projectname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectlevel" label="项目级别" width="80px" sortable="custom" sort-by="projectlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectmanager" label="项目经理" width="80px" sortable="custom" sort-by="projectmanager" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispprojectstate" label="项目状态" width="80px" sortable="custom" sort-by="projectstate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="bidcycle" label="项目周期(天)" width="105px" sortable="custom" sort-by="bidcycle" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="planstartdate" label="计划开始日期" width="105px" sortable="custom" sort-by="planstartdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="planenddate" label="计划结束日期" width="105px" sortable="custom" sort-by="planenddate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="actualenddate" label="实际结项日期" width="105px" sortable="custom" sort-by="actualenddate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="participatemoney" label="可参与金额(万元)"  width="130px" sortable="custom" sort-by="participatemoney" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="projectendmoney" label="结项金额(万元)"  width="115px" sortable="custom" sort-by="projectendmoney" align="right" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="sponsor" label="Sponsor" width="75px" sortable="custom" sort-by="sponsor" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="owner" label="Owner" width="75px" sortable="custom" sort-by="owner" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="decisionusername" label="决策组人员" width="150px" sortable="custom" sort-by="decisionusername" align="left" header-align="center" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="background" label="项目背景概述" width="240px" sortable="custom" sort-by="background" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="target" label="项目目标" width="200px" sortable="custom" sort-by="target" align="center" header-align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="summary" label="总体策划" width="200px" sortable="custom" sort-by="summary" align="center" header-align="left" :show-overflow-tooltip="true"></el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" type="flex" ref="pager" align="bottom">
        <el-col :span="12" style="margin-bottom:5px;">
          <el-col style="background-color:#D80A1E;height: 20px;width:20px;margin-left:10px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            项目超期
          </el-col>
          <el-col style="background-color:#FF8C2E;height: 20px;width:20px" :offset="0"> </el-col>
          <el-col class="projectStateContext milepost" :offset="0">
            里程碑及任务超期
          </el-col>
          <el-col style="background-color:#0000FF;height: 20px;width:20px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            流程超期
          </el-col>
          <el-col style="background-color:#B8860B;height: 20px;width:20px" :offset="0"> </el-col>
          <el-col class="projectStateContext" :offset="0">
            任务超期
          </el-col>
        </el-col>
        <el-col :span="14">
          <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
        </el-col>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
    </div>
    <index-for-file-comp ref="indexForFileComp" :projectcode="projectcode"></index-for-file-comp>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import { validateNull } from '@tapui/utils/validate'
import tlEdit from './edit'
import IndexForFileComp from "../projectInfo/indexForFileComp"
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
import { filterObjectNull, rmbFormat } from '@tapui/utils/util'
export default {
  name: 'mpmProject',
  mixins: [mixin_list],
  components: { IndexForFileComp, tlEdit },
  data() {
    return {
      projectlevelList: [],
      urlParam: '?',
      description: '项目归档-列表查询',
      urlPrefix: '/mpm/projectpolymerization/',
      url: {
        queryCodeList: '/mpm/projectpolymerization/dataCodeList',
        list: '/mpm/projectpolymerization/projectFileList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'mpmproject.ABNORMALSTATE',
        sord: 'desc'
      },
      projectcode: ''
    }
  },
  methods: {
    /** 获取查询参数 */
    getQueryParams() {
      let param = {}
      // 获取首页跳转参数
      if (this.urlParam.length !== 0) {
        this.urlParam = window.location.search
      }
      if (this.projectlevelList.length > 0) {
        param.qry_projectlevel = this.projectlevelList.join(',')
      } else if (this.urlParam !== '?' && this.urlParam.length > 0) {
        //  如果收页跳转参数不为空,那么根据首页参数查询
        var projectlevel = this.urlParam.substr(1)
        this.projectlevelList = [projectlevel]
        param.qry_projectlevel = projectlevel
        //  清除首页参数
        this.urlParam = ''
      }
      if (this.superQueryParams) {
        param['superQueryParams'] = encodeURI(this.superQueryParams)
      }
      Object.assign(param, this.queryParam, this.sorterInfo, this.filtersInfo)
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      return filterObjectNull(param)
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    /** 列表数据加载开始 */
    loadData(paramMap) {
      // 得到加载分页
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      if (!this.beforeLoadData()) return
      // 查询条件
      var params = this.getQueryParams()
      // 数据查询
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
            // 初始化自定义列
            if (typeof this.$refs.toolbar !== 'undefined') {
              this.$refs.toolbar.doInitTableColumn()
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterLoadData()
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    // 行颜色
    tableRowStyle(row, index) {
      if (row.row.abnormalstate === 3) {
        return { 'background-color': 'rgb(235,75,75)', color: 'white' }
      } else if (row.row.abnormalstate === 2) {
        return { 'background-color': 'rgb(255,140,46)', color: 'white' }
      } else if (row.row.abnormalstate === 1) {
        return { 'background-color': 'rgb(184,134,11)', color: 'white' }
      } else if (row.row.abnormalstate === 4) {
        return { 'background-color': '#0000FF', color: 'white' }
      }
    },
    // 双击打开项目追踪页面
    doRowDbClick(row, column, event) {
      // this.$router.push({
      //   name: 'projectInfoFileIndex',
      //   query: {
      //     id: row.id,
      //     code: row.projectcode
      //   }
      // })
      this.projectcode = row.projectcode
      this.$nextTick(() => {
        this.$refs.indexForFileComp.id = row.id
        this.$refs.indexForFileComp.visible = true
      })
    }
  }
}
</script>
<style>
.el-scrollbar__view {
  height: 98%;
}
.app-main {
  height: 100%;
}
</style>
<style scoped>
.app-container >>> .el-table tbody tr:hover > td {
  background-color: transparent !important;
}

.app-container {
  height: 100%;
  padding: 10px;
  margin: 12px;
  background: white;
  border-radius: 5px;
}
</style>
